using System;
using System.Collections;
using System.Xml;
using System.Reflection;

namespace BEGDC.CC.BL.Workflow
{
	/// <summary>
	/// Summary description for ProcessNode.
	/// </summary>
	[Serializable]
	public class ProcessState : System.IComparable, System.ICloneable
	{
		/// <summary>
		/// Constructor
		/// </summary>
		public ProcessState()
		{
			this.sub_states = new ProcessStateList();
		}

		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="nodeKey">node key</param>
		public ProcessState(string nodeKey)
		{
			this.key = nodeKey;
			this.sub_states = new ProcessStateList();
		}

		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="node">process state Xml node</param>
		public ProcessState(XmlNode node)
		{
			this.key = node.Attributes["key"].Value;
			this.class_name = node.Attributes["classname"].Value;
			this.path_name = node.Attributes["pathname"].Value;

			this.sub_states = new ProcessStateList();

			for(int i=0; i< node.ChildNodes.Count; i++)
			{
				XmlNode chnode = node.ChildNodes[i];
				ProcessState chstate = new ProcessState(chnode);
				this.sub_states.Add(chstate);
			}
		}

		private string key;
		/// <summary>
		/// Node Key
		/// </summary>
		public string Key
		{
			get
			{
				return this.key;
			}
			set
			{
				this.key = value;
			}
		}

		private Int64 id;
		/// <summary>
		/// Node ID
		/// </summary>
		public Int64 ID
		{
			get
			{
				return this.id;
			}
			set
			{
				this.id = value;
			}
		}

		private ProcessStateList sub_states;
		/// <summary>
		/// Children States
		/// </summary>
		public ProcessStateList ChildrenStates
		{
			get
			{
				return this.sub_states;
			}
			set
			{
				this.sub_states = value;
			}
		}

		private string class_name;
		/// <summary>
		/// class name of mapping user control
		/// </summary>
		public string ClassName
		{
			get
			{
				return this.class_name;
			}
			set
			{
				this.class_name = value;
			}
		}

		private string path_name;
		/// <summary>
		/// Path of mapping user control
		/// </summary>
		public string Path
		{
			get
			{
				return this.path_name;
			}
			set
			{
				this.path_name = value;
			}				
		}

		private ProcessStateEnum state;
		/// <summary>
		/// Process State
		/// </summary>
		public ProcessStateEnum State
		{
			get
			{
				return this.state;
			}
			set
			{
				this.state = value;
			}
		}


		#region IComparable Members

		/// <summary>
		/// Compares the current instance with another object of the same type.
		/// </summary>
		/// <param name="obj">An object to compare with this instance.</param>
		/// <returns>A 32-bit signed integer that indicates the relative order of the comparands.</returns>
		public int CompareTo(object obj)
		{
			ProcessState ps = (ProcessState)obj;
			return ps.key.CompareTo(ps.key);
		}

		#endregion

		#region ICloneable Members
		/// <summary>
		/// Creates a new object that is a copy of the current instance.
		/// </summary>
		/// <returns>new object</returns>
		public object Clone()
		{
			ProcessState newobj = new ProcessState();
			newobj.key = this.key;
			newobj.path_name = this.path_name;
			newobj.class_name = this.class_name;
			newobj.sub_states = (ProcessStateList)this.sub_states.Clone();
			return newobj;
		}

		#endregion


	}

	public enum ProcessStateEnum
	{
		Default,
		Finished,
		OnGoing,
		Tailored
	}
}
